import React from 'react'
import {
  PickerView,
  type PickerViewProps,
} from '../PickerView'
import { useColumnsFn } from './utils'

export type CascadePickerOption = {
  label: string
  value: string
  children?: CascadePickerOption[]
}

export type CascadePickerViewProps = Omit<PickerViewProps, 'columns'> & {
  /** 树形选项数据 */
  options: CascadePickerOption[]
}

export const CascadePickerView: React.FC<CascadePickerViewProps> = (props) => {
  const { options, ...pickerProps } = props
  const columnsFn = useColumnsFn(options)

  return (
    <PickerView
      {...pickerProps}
      columns={columnsFn}
    />
  )
}
